package com.example.administrator.printoutindemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.printoutindemo.CangKuActivity;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.bean.InKuBean_ZhiJianWanCheng;
import com.example.administrator.printoutindemo.mvp.ui.activity.CangKu_ZhiJianWanChengActivity;

import java.util.ArrayList;
import java.util.List;


public class InKuAdapter_ZhiJianWanCheng extends BaseAdapter {

    Context context;
    List<InKuBean_ZhiJianWanCheng> mlists = new ArrayList<>();
    LayoutInflater inflater;

    public InKuAdapter_ZhiJianWanCheng(Context context, List<InKuBean_ZhiJianWanCheng> mlists) {
        this.context = context;
        this.mlists = mlists;
        this.inflater = LayoutInflater.from(context);
    }

    public void shua() {
        if (mlists == null)
            mlists = new ArrayList<>();
        notifyDataSetInvalidated();
    }

    @Override
    public int getCount() {
        return mlists.size();
    }

    @Override
    public Object getItem(int i) {
        return mlists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            Log.e("hh====================", "11111");
            view = getInflater().inflate(R.layout.item_ru_ku_zhi_jian_wan_cheng, null);
            holder = new ViewHolder();
            holder.tv_xiang_mu_ming_cheng = view.findViewById(R.id.tv_xiang_mu_ming_cheng);
            holder.tv_wu_liao_ming_cheng = view.findViewById(R.id.tv_wu_liao_ming_cheng);
            holder.tv_shu_liang = view.findViewById(R.id.tv_shu_liang);
            holder.tv_zhi_jian_di_dian = view.findViewById(R.id.tv_zhi_jian_di_dian);
            holder.tv_si_ji_xing_ming = view.findViewById(R.id.tv_si_ji_xing_ming);
            holder.tv_si_ji_dian_hua = view.findViewById(R.id.tv_si_ji_dian_hua);
            holder.tv_cang_ku_xuan_ze = view.findViewById(R.id.tv_cang_ku_xuan_ze);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_xiang_mu_ming_cheng.setText(mlists.get(i).getProjectname());
        holder.tv_wu_liao_ming_cheng.setText(mlists.get(i).getMaterial());
        holder.tv_shu_liang.setText(mlists.get(i).getNums());
        holder.tv_zhi_jian_di_dian.setText(mlists.get(i).getQualityplace());
        holder.tv_si_ji_xing_ming.setText(mlists.get(i).getDrivername());
        holder.tv_si_ji_dian_hua.setText(mlists.get(i).getTrunknumber());


        holder.tv_cang_ku_xuan_ze.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("item_data", mlists.get(i));
                Intent intent = new Intent(context, CangKu_ZhiJianWanChengActivity.class);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });

        return view;
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    public void addAll(List<InKuBean_ZhiJianWanCheng> sdc) {
        mlists.addAll(sdc);
        notifyDataSetChanged();
    }

    public void clearData() {
        mlists.clear();
    }

    class ViewHolder {
        TextView tv_xiang_mu_ming_cheng, tv_wu_liao_ming_cheng, tv_shu_liang, tv_zhi_jian_di_dian, tv_si_ji_xing_ming, tv_si_ji_dian_hua, tv_cang_ku_xuan_ze;
    }
}
